public class StringOptimization {
    public static void main (String args[]){
        String variable[] = new String[50000];
        for (int i = 0; i < 50000; i++) {
            variable[i] = "s"+i;
        }
        long startTime0 = System.currentTimeMillis();
        for (int i = 0; i < 50000; i++) {
            variable[i]= "hello";
        }
        long endTime0 = System.currentTimeMillis();
        System.out.println("通过String关键词创建字符串"+":"+(endTime0-startTime0)+"毫秒");
        long startTime1 = System.currentTimeMillis();
        for (int i = 0; i < 50000; i++) {
            variable[i]= new String("hello");
        }
        long endTime1 = System.currentTimeMillis();
        System.out.println("通过new关键字创建字符串"+":"+(endTime1-startTime1)+"毫秒");
        long startTime2 = System.currentTimeMillis();
        for (int i = 0; i < 50000; i++) {
            variable[i]= "hello";
        }
        long endTime2 = System.currentTimeMillis();
        System.out.println("通过String关键词创建字符串"+":"+(endTime2-startTime2)+"毫秒");

    }
}
